package com.richman.utils;


import java.math.BigDecimal;
import java.text.SimpleDateFormat;
public class Common {
	
	public static boolean isNum(String str){
        try {
            new BigDecimal(str);
            return true;
        } catch (Exception e) {
            return false;
        }
	}
	
	public static String pankouStr(String str){
		
		try{
			
			
			if(str != null && !str.equals("")){
				
				if(str.contains("H")) {
					str = str.replace("H", "");
					str = str.replace(" ", "");
					
					if(str.contains("/")) {
						double r1 = Double.parseDouble(str.split("/")[0]);
						double r2 = Double.parseDouble(str.split("/")[1]);
						return Double.toString((r1+r2)/2);
					}else {
						return str;
					}
					
				}
				
				if(str.contains("C")) {
					str = str.replace("C", "");
					str = str.replace(" ", "");
					
					if(str.contains("/")) {
						double r1 = Double.parseDouble(str.split("/")[0]);
						double r2 = Double.parseDouble(str.split("/")[1]);
						return Double.toString(0.0 - (r1+r2)/2);
					}else {
						return "-" + str;
					}
					
				}
				
				
				
				if(str.contains("O")) {
					str = str.replace("O", "");
					str = str.replace(" ", "");
					
					if(str.contains("/")) {
						double r1 = Double.parseDouble(str.split("/")[0]);
						double r2 = Double.parseDouble(str.split("/")[1]);
						return Double.toString((r1+r2)/2);
					}else {
						return str;
					}
				}
				
				
				if(str.contains("/")||Common.isNum(str)) {
					str = str.replace("O", "");
					str = str.replace(" ", "");
					
					if(str.contains("/")) {
						double r1 = Double.parseDouble(str.split("/")[0]);
						double r2 = Double.parseDouble(str.split("/")[1]);
						return Double.toString((r1+r2)/2);
					}else {
						return str;
					}
				}
				
				

			}else {
				return "";
			}
			
		}catch(Exception e){
			e.printStackTrace();
			
		}
		
		return "";
	}
	
	
	public static void logOut(String str) {
		
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		
		System.out.println(df.format(System.currentTimeMillis()) + "   :"   + str);
		
	}

}

